<?php

namespace app\common\model\xiluhouse;

use think\Model;

class RentalContactView extends Model
{
    // 表名
    protected $name = 'xiluhouse_rental_contact_view';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    // 追加属性
    protected $append = [
        
    ];

    /**
     * 获取用户当日查看次数
     */
    public static function getTodayViewCount($user_id)
    {
        return self::where('user_id', $user_id)
            ->where('view_date', date('Y-m-d'))
            ->count();
    }

    /**
     * 记录查看
     */
    public static function recordView($user_id, $rental_id, $contact_id)
    {
        return self::create([
            'user_id' => $user_id,
            'rental_id' => $rental_id,
            'contact_id' => $contact_id,
            'view_date' => date('Y-m-d')
        ]);
    }
} 